package com.example.homelicaisystem.control;

import com.example.homelicaisystem.entity.Card;
import com.example.homelicaisystem.entity.SelectResult;
import com.example.homelicaisystem.services.CardService;
import com.example.homelicaisystem.utils.HandleMoney;
import com.example.homelicaisystem.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/card")
@RestController
@Slf4j
public class CardControl {
    private final CardService cardService;

    public CardControl(CardService cardService) {
        this.cardService = cardService;
    }

    @PostMapping("/select")
    public Result<List<SelectResult>> selectCard() {
        log.debug("收到select请求");
        return Result.ok(cardService.selectCard());
    }

    @PostMapping("/create")
    public Result<?> createCard(@RequestBody Card data) {
        log.debug("收到create请求");
        //拿到后台处理时，金钱单位为最小单位 分
        data.setMoney(HandleMoney.backendMoney(data.getMoney()));
        cardService.createCard(data);
        return Result.ok(null);
    }


}
